// hello.ts
import * as readline from 'readline/promises';

let stock: number = 100;
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});


async function main() {
    while (true) {
        const order_type = await rl.question('请输入出入库类型,出库请输入1, 入库请输入2，输入其他则退出：');
        if (order_type == '1' || order_type == '2') {
            const num_str = await rl.question("请输入 出入库的数量：");
            const num = Number(num_str);
            if (isNaN(num)) {
                console.log('请输入有效的数字！');
            } else {
                if (order_type == '1') {
                    stock -= num;
                } else {
                    stock += num;
                }
            }
        } else {
            break
        }
    }
}

main()
    .then(() => {
        rl.close()
        console.log('✅ main 执行完毕');
        console.log('当前库存为：', stock)
    })
    .catch(err => console.error('❌ 出错了：', err));